<template>
  <div>
    <Search :search="search" :reset="reset">
      <template v-slot:body>
        <el-form-item label="组织" prop="org_code">
          <el-select v-model="query.fuseorgid_number" name="fuseorgid_number" placeholder="请选择组织" clearable>
            <el-option :label="item.label" :value="item.value" v-for="item in orgList" :key="item.value" />
          </el-select>
        </el-form-item>
        <el-form-item label="仓库编码" prop="fnumber">
          <el-input v-model="query.fnumber" name="fnumber" clearable />
        </el-form-item>
        <el-form-item label="仓库名称" prop="fname">
          <el-input v-model="query.fname" name="fname" clearable />
        </el-form-item>
      </template>
    </Search>

    <div class="table-default">
      <!-- <Operate :show="open"> -->
      <!-- <template #operate>
          <el-button type="primary" @click="print()">打印</el-button>
        </template> -->
      <!-- </Operate> -->
      <!-- 新增 -->

      <el-table :data="tableData" class="mt-3" v-loading="loading" row-key="id" default-expand-all :tree-props="{ children: 'children' }" border>
        <!-- <el-table-column type="selection" width="55" /> -->
        <!-- <el-table-column prop="id" label="行号" /> -->
        <el-table-column prop="fuseorgid_name" label="组织名称" />
        <!-- <el-table-column prop="fmaterial" label="仓库内码" /> -->
        <el-table-column prop="fnumber" label="仓库编码" />
        <el-table-column prop="fname" label="仓库名称" />
        <!-- <el-table-column prop="fuseorgid_number" label="使用组织编码" min-width="200" /> -->
      </el-table>
      <Paginate />
    </div>

    <Dialog v-model="visible" :title="title" destroy-on-close>
      <Create @close="close(reset)" :primary="id" :api="api" />
    </Dialog>
  </div>
</template>

<script lang="ts" setup>
import { computed, onMounted, ref, reactive } from 'vue'
import Create from './create.vue'
import { useGetList } from '/admin/composables/curd/useGetList'
import { useDestroy } from '/admin/composables/curd/useDestroy'
import { useOpen } from '/admin/composables/curd/useOpen'
import http from '/admin/support/http'
import { ElMessage } from 'element-plus'
import { setTableHeight } from '/admin/utils/setHeight.js'

const api = 'warehouse/datatype'

const { data, query, search, reset, loading } = useGetList(api, false)
const { destroy, deleted } = useDestroy()
const { open, close, title, visible, id } = useOpen()

const tableData = computed(() => data.value?.data)

let idArray = reactive([])
let barcodeList = ref([])
const handleSelectionChange = (val: any) => {
  for (const obj of val) {
    idArray.push(obj.id)
  }
  console.log(idArray)
}

const print = () => {
  console.log('打印', idArray)
  if (idArray.length != 0) {
    getPrint(idArray)
  } else {
    ElMessage.warning('请选择仓库！')
  }
}

const getPrint = arr => {
  const data = {
    id: arr,
  }
  console.log(data)

  http.post('/warehouse/Printinterface', data).then(r => {
    console.log(r)
    let res = r.data.data
    ElMessage.success(res.message)
    barcodeList.value = res.data
  })
}

const orgList = ref([])

const getorg = () => {
  http.get(`options/Org`).then(r => {
    console.log('组织数据', r.data)
    orgList.value = r.data.data
  })
}

getorg()

onMounted(() => {
  search()
  deleted(reset)
  setTableHeight('.table-default')
})
</script>

<style>
.el-table {
  height: 80%;
}
</style>
